package com.example.service.impl;

import com.example.dao.EmpDAOMapper;
import com.example.entity.Emp;
import com.example.service.EmpService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

@Service
@Transactional
public class EmpServiceImpl implements EmpService {

    @Resource
    private EmpDAOMapper empDAO;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public Emp findById(String id) {
        return empDAO.findById(id);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Emp> findAll() {
        return empDAO.findAll();
    }

    @Override
    public void update(Emp Emp) {
        empDAO.update(Emp);
    }

    @Override
    public void save(Emp Emp) {
        Emp.setId(UUID.randomUUID().toString());
        empDAO.save(Emp);
    }

    @Override
    public void delete(String id) {
        empDAO.delete(id);
    }
}
